package com.sykj.config;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * @ClassName WeChatConfig
 * @Description TODO 微信配置类
 * @Author vains
 * @Date 2019/5/25 21:33
 * @Version 1.0
 **/
@Data
@Configuration
@NoArgsConstructor
@AllArgsConstructor
public class WeChatConfig {

    /**
     * 模板消息id
     */
    public String templateId = "i-YxfJ9Jys2seFzTtFzRQitA_CV9kJcyRrUn8i8U8CE";

    /**
     *开放平台appid
     */
    @Value("${wxopen.appid}")
    private String appid;

    /**
     *开放平台appsecret
     */
    @Value("${wxopen.appsecret}")
    private String appsecret;

    /**
     *开放平台回调地址
     *//*
    @Value("${wxopen.redirect_url}")
    private String redirect_url;*/

    /**
     * 公众平台微信登录回调
     */
    @Value("${wxopen.redirectUrl}")
    private String redirectUrl;

    /**
     * 微信支付回调地址(通知地址)
     */
    public static final String NOTIFY_URL = "https://vains.ngrok.xiaomiqiu.cn/notifyUrl";

    /**
     * 微信支付 商户号
     */
    public static final String MCHID = "7551000001";

    /**
     * 微信支付 商户秘钥
     */
    public static final String KEY = "9d101c97133837e13dde2d32a5054abb";

    /**
     * 微信支付请求地址，正式号需换成正式地址
     */
    public static final String GATEWAY = "https://pay.swiftpass.cn/pay/gateway";

    /**
     * @Author vains
     * @Description //TODO 跳转到扫码登录地址的url
     * @Date 2019/5/25 21:41 
     * @Param [accessPage]
     * @return java.lang.String
     **//*
    public String getLoginUrl(String accessPage){
        try {
            return "https://open.weixin.qq.com/connect/qrconnect?appid=" +appid+
                    "&redirect_uri=" + URLEncoder.encode(redirect_url, "utf-8")+
                    "&response_type=code&scope=snsapi_login&" +
                    "state="+ URLEncoder.encode(accessPage, "utf-8") +"#wechat_redirect";
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return "";
    }*/
    
    /**
     * @Author vains
     * @Description //TODO 获取accessToken的url
     * @Date 2019/5/25 21:41 
     * @Param [code]
     * @return java.lang.String
     **/
    public String getAccessTokenUrl(String code){
        return "https://api.weixin.qq.com/sns/oauth2/access_token?" +
                "appid=" +appid+
                "&secret=" +appsecret+
                "&code="+code+"&grant_type=authorization_code";
    }
    
    /**
     * @Author vains
     * @Description //TODO 获取用户信息的url
     * @Date 2019/5/25 22:16
     * @Param [accessToken, openid]
     * @return java.lang.String
     **/
    public String getUserInfoUrl(String accessToken, String openid){
        return "https://api.weixin.qq.com/sns/userinfo?" +
                "access_token=" + accessToken+
                "&openid="+ openid;
    }

}
